package suites.queue {
	import suites.queue.mock.ErrorQable;

	import org.flexunit.asserts.assertEquals;
	import org.splink.library.queue.IQ;
	import org.splink.library.queue.QEvent;

	import flash.events.Event;

	/**
	 * @author Max Kugland
	 */
	public class QErrorTest extends AbstractQTest {

		[Test (async)]
		public function testError() : void {
			var asyncFnc : Function = handleAsync(1500);
			_q.finalize(); // unregister listeners from AbstractQTest
			
			var errorCount : int = 0;

			_q.register(QEvent.ERROR, function(e : QEvent):void {
				errorCount++;
			});
			_q.register(QEvent.COMPLETE, function(e : QEvent):void {
				assertEquals(2, errorCount);
				asyncFnc(new Event(Event.COMPLETE));
			});
			
			var q : IQ = createQ(1);			var q1 : IQ = createQ(2);			q1.add(createQ(1));			q1.add(new ErrorQable());
			q.add(q1);			q.add(new ErrorQable());
			_q.add(q);
			_q.start();
		}
	}
}
